#include <iostream>
#include <sys/eventfd.h>
#include <stdint.h>
#include <cstring>
#include <unistd.h>

int main()
{
    int efd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
    if (efd < 0)
    {
        perror("eventfd failed");
        return -1;
    }
    uint64_t val = 1;
    write(efd, &val, sizeof(val));  //写一次就代表通知一次事件
    write(efd, &val, sizeof(val));
    write(efd, &val, sizeof(val));
    uint64_t res1 = 0;
    read(efd, &res1, sizeof(res1));
    std::cout << res1 << std::endl;
    uint64_t res2 = 0;
    read(efd, &res2, sizeof(res2));
    std::cout << res2 << std::endl;
    close(efd);
    return 0;
}